import { changeLinesPositionBasedBindOverlay, removeLinesOfOverlay } from "../../widgets/line-plot/drawLine"
import { toRaw } from "vue"
import { viewerId, rightViewerId } from "../../components/de-work/map"

/**
 * 图层的事件配置
 */
export default {
  [viewerId]: {
    equipPlotLayer: [
      {
        type: "EDIT_START",
        callback: (layer, options) => {
          // layer为当前layer本身
          const {
            showEditor = window.$showEditor,
            store = window.$store
          } = options
          return (overlay) => {
            console.log("编辑开始--", overlay)
            showEditor({
              name: "overlay-editor",
              data: {
                overlay: toRaw(overlay)
              }
            })
            store.commit("entity/SET_EditingEntity", {
              entity: toRaw(overlay),
              isEditing: true
            })
          }
        }
      },
      {
        type: "EDIT_STOP",
        callback: (layer, options) => {
          return (overlay) => {
            console.log("编辑停止", overlay)
            window.$disableWidget("overlay-editor")
          }
        }
      },
      {
        type: "EDITING",
        callback: (layer, options) => {
          return (pickInfo) => {
            const {
              overlay,
              target
            } = pickInfo
            changeLinesPositionBasedBindOverlay(overlay)
          }
        }
      },
      {
        type: "ADD_OVERLAY",
        callback: () => {
          return (e) => {
            console.log("添加对象", e)
          }
        }
      },
      {
        type: "REMOVE_OVERLAY",
        callback: () => {
          return (overlay) => {
            // 将实体关联的线删除
            removeLinesOfOverlay(overlay)
            console.log("删除对象", overlay)
          }
        }
      }
    ],
    actionPlotLayer: [
      {
        type: "EDIT_START",
        callback: () => {
          return (overlay) => {
            console.log("actionPlotLayer start", overlay)
            window?.$showEditor({
              name: "action-editor",
              data: {
                overlay: toRaw(overlay)
              }
            })
            window?.$store.commit("entity/SET_EditingEntity", {
              entity: toRaw(overlay),
              isEditing: true
            })
          }
        }
      },
      {
        type: "EDIT_STOP",
        callback: (layer, options) => {
          return (overlay) => {
            console.log("编辑停止", overlay)
            window?.$disableWidget("action-editor")
          }
        }
      },
      {
        type: "EDITING",
        callback: (layer, options) => {
          return (pickInfo) => {
            const {
              overlay,
              target
            } = pickInfo
            changeLinesPositionBasedBindOverlay(overlay)
          }
        }
      },
      {
        type: "ADD_OVERLAY",
        callback: () => {
          return (e) => {
            console.log("添加对象", e)
            window.$tooltipAutoHide = true
          }
        }
      },
      {
        type: "REMOVE_OVERLAY",
        callback: () => {
          return (overlay) => {
            // 将实体关联的线删除
            removeLinesOfOverlay(overlay)
            console.log("删除对象", overlay)
          }
        }
      }
    ]
  }
}
